package com.three.digit.tools;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;

public class ZgJg {

	public static void main(String[] args) {
	   List<int[]> list = getSixNum();
	   try {
		   File f = new File("F:\\2009-2-5.txt");
		   BufferedWriter out = new BufferedWriter(new FileWriter(f));
		   for(int i=0;i<list.size();i++){
			   int[] str = (int[])list.get(i);
			   out.write(str[0]+"-"+str[1]+"-"+str[2]+"-"+str[3]+"-"+str[4]+"-"+str[5]);
			   out.newLine();
		   }
		   out.write(String.valueOf(list.size()));
		   out.close();
	   }catch (Exception e) {
			e.printStackTrace();
	   }
	   //System.out.println(str[0]+"-"+str[1]+"-"+str[2]+"-"+str[3]+"-"+str[4]+"-"+str[5]);
		
		System.out.println(list.size());
	}

	public static List<int[]> getSixNum() {
		List<int[]> list = new ArrayList<int[]>();
		for (int a = 1; a < 29; a++) {
			for (int b = a + 1; b < 30; b++) {
				for (int c = b + 1; c < 31; c++) {
					for (int d = c + 1; d < 32; d++) {
						for (int e = d + 1; e < 33; e++) {
							for (int f = e + 1; f < 34; f++) {
								int[] str = new int[6];
								str[0] = a;
								str[1] = b;
								str[2] = c;
								str[3] = d;
								str[4] = e;
								str[5] = f;
								if (judgeL(str,0)) {
									if (judgeH(str)) {
										if(judgeSanFen(str)){
											if (judgeJO(str, 4)) {
												if (judgeAvg(str, 13, 21)) {
													if (judgeLianHao(str, 1, 1)) {
														if (judgeAppear(1, str, 5,11, 15, 17, 18, 28)) {
															if (judgeL(str, 2)) {
																//if (judgeConfirm(str, 5, 11,15, 17, 18,28)) {
																	list.add(str);
																//}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		return list;
	}

	/**
	 * �ж��Ƿ���� ���max��������Ϳ�һ���������У������max��
	 * 
	 * @param str
	 * @return
	 */
	public static boolean judgeL(int[] str,int max) {
		boolean flag = false;
		int num=0,a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
		for (int i = 0, ii = str.length; i < ii; i++) {
			switch (str[i] % 6) {
			case 1:
				a++;
				break;
			case 2:
				b++;
				break;
			case 3:
				c++;
				break;
			case 4:
				d++;
				break;
			case 5:
				e++;
				break;
			case 0:
				f++;
				break;
			}
		}
		if (a == 0)
			num++;
		if (b == 0)
			num++;
		if (c == 0)
			num++;
		if (d == 0)
			num++;
		if (e == 0)
			num++;
		if (f == 0)
			num++;
		if(max==0){
			if (num>=1&&num<=3)
				flag = true;
		}else{
			if (num == max)
				flag = true;
		}
		return flag;
	}

	/**
	 * �ж��Ƿ���� ��Ϳ�һ��
	 * 
	 * @param str
	 * @return
	 */
	public static boolean judgeH(int[] str) {
		boolean flag = false;
		if ((str[1] - str[0]) >= 6)
			flag = true;
		if ((str[2] - str[1]) >= 6)
			flag = true;
		if ((str[3] - str[2]) >= 6)
			flag = true;
		if ((str[4] - str[3]) >= 6)
			flag = true;
		if ((str[5] - str[4]) >= 6)
			flag = true;
		return flag;
	}

	/**
	 * �ж�������е���ż�� ������������������ż��Ϊmax
	 * 
	 * @param str
	 * @param max
	 * @return
	 */
	public static boolean judgeJO(int[] str, int max) {
		boolean flag = true;
		int j = 0, o = 0;
		for (int i = 0, ii = str.length; i < ii; i++) {
			switch (str[i] % 2) {
			case 1:
				j++;
				break;
			case 0:
				o++;
				break;
			}
		}
		if (j > max || o > max)
			flag = false;
		return flag;
	}

	/**
	 * �ж�������ƽ���� ����ƽ������СΪmix���Ϊmax
	 * 
	 * @param str
	 * @param mix
	 * @param max
	 * @return
	 */
	public static boolean judgeAvg(int[] str, int mix, int max) {
		boolean flag = false;
		int value = (str[0] + str[1] + str[2] + str[3] + str[4] + str[5]) / 6;
		if (value >= mix && value <= max)
			flag = true;
		return flag;
	}

	/**
	 * �ж�l����  ������ָ���mixΪ��Сֵ maxΪ���ֵ
	 * 
	 * @param str
	 * @param mix
	 * @param max
	 * @return
	 */
	public static boolean judgeLianHao(int[] str, int mix, int max) {
		boolean flag = false;
		int num = 0;
		if ((str[1] - str[0]) == 1)
			num++;
		if ((str[2] - str[1]) == 1)
			num++;
		if ((str[3] - str[2]) == 1)
			num++;
		if ((str[4] - str[3]) == 1)
			num++;
		if ((str[5] - str[4]) == 1)
			num++;
		if (num >= mix && num <= max)
			flag = true;
		return flag;
	}
	
	/**
	 * �ж�������� ÿ������������λ�� ������һλ
	 * @param str
	 * @return
	 */
	public static boolean judgeSanFen(int[] str){
		boolean flag = false;
		int a=0,b=0,c=0;
		for(int i=0,ii=str.length;i<ii;i++){
			if(str[i]>=1&&str[i]<=11)a++;
			if(str[i]>=12&&str[i]<=22)b++;
			if(str[i]>=23&&str[i]<=33)c++;
		}
		if(a<5&&b<5&&c<5&&a>0&&b>0&&c>0)
			flag = true;
		return flag;
	}
	
	
	/**
	 * �ж��ϴγ��ֵĸ��� �����ظ����ֵΪmax��
	 * 
	 * @param max
	 * @param str
	 * @param a
	 * @param b
	 * @param c
	 * @param d
	 * @param e
	 * @param f
	 * @return
	 */
	public static boolean judgeAppear(int max, int[] str, int a, int b, int c,
			int d, int e, int f) {
		boolean flag = false;
		int num = 0;
		for (int i = 0, ii = str.length; i < ii; i++) {
			if (str[i] == a)
				num++;
			if (str[i] == b)
				num++;
			if (str[i] == c)
				num++;
			if (str[i] == d)
				num++;
			if (str[i] == e)
				num++;
			if (str[i] == f)
				num++;
		}
		if (num <= max)
			flag = true;
		return flag;
	}

	public static boolean judgeConfirm(int[] str, int a, int b, int c, int d,
			int e, int f) {
		boolean flag = false;
		int num = 0;
		if (str[0] == a)
			num++;
		if (str[1] == b)
			num++;
		if (str[2] == c)
			num++;
		if (str[3] == d)
			num++;
		if (str[4] == e)
			num++;
		if (str[5] == f)
			num++;
		if (num == 6)
			flag = true;
		return flag;
	}
}
